package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SignUpAddDTO;
import org.jsola.hr.dto.SignUpUpdateDTO;
import org.jsola.hr.entity.SignUpDO;
import org.jsola.hr.query.SignUpQuery;
import org.jsola.hr.service.ISignUpService;
import org.jsola.hr.vo.SignUpVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 公司首页报名表
 *
 * @author zhr
 */
@Component
public class SignUpTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISignUpService signUpService;

    /**
     * 生成add测试数据
     * @return SignUpAddDTO
     */
    public SignUpAddDTO getSignUpAddDTO(){
        SignUpAddDTO signUpAddDTO = new SignUpAddDTO();
        signUpAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        signUpAddDTO.setLink(getRandomValue("varchar",500));
        signUpAddDTO.setImgUrl(getRandomValue("varchar",500));
        return signUpAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SignUpUpdateDTO
     */
    public SignUpUpdateDTO getSignUpUpdateDTO(SignUpVO signUpVO){
        return signUpService.selectDOById(signUpVO.getId(), SITE_ID).to(SignUpUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SignUpQuery
     */
    public SignUpQuery getSignUpQuery() {
        SignUpQuery signUpQuery = new SignUpQuery();
        List<SignUpDO> signUpDOList = signUpService.list(new SignUpDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(signUpDOList)) {
            SignUpDO signUpDO = signUpDOList.get(0);
            signUpQuery = signUpDO.to(SignUpQuery.class);
        }
        return signUpQuery;
    }

    /**
     * 保存示例
     * @return SignUpVO
     */
    public SignUpVO saveSignUpExample(){
        SignUpAddDTO addDTO = this.getSignUpAddDTO();
        SignUpVO signUpVO = signUpService.save(addDTO,buildTokenUser());
        return signUpVO;
    }


}

